using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Xml.Serialization;
using GraphAlgsPresentation.Core;
using System.ComponentModel;

namespace GraphAlgsPresentation.ScriptLibrary
{
    /// <summary>
    /// Provides a change text font command
    /// </summary>
    [Serializable]
    public class ChangeTextFont : Command
    {
        private int _index;

        /// <summary>
        /// Gets or sets the index.
        /// </summary>
        /// <value>The index.</value>
        public int Index
        {
            get { return _index; }
            set { _index = value; }
        }

        private Font _font;

        /// <summary>
        /// Gets or sets the font.
        /// </summary>
        /// <value>The font.</value>
        [XmlIgnore]
        public Font Font
        {
            get { return _font; }
            set { _font = value; }
        }

        /// <summary>
        /// Gets or sets the XML font.
        /// </summary>
        /// <value>The XML font.</value>
        [Browsable(false)]
        public XmlFont XmlFont
        {
            get { return new XmlFont(this.Font); }
            set { this.Font = value.ToFont(); }
        }

        private Font oldFont;
        /*[XmlIgnore]
        public Font OldFont
        {
            get { return oldFont; }
            set { oldFont = value; }
        }
	
        public XmlFont XmlOldFont
        {
            get { return new XmlFont(this.OldFont); }
            set { this.OldFont = value.ToFont(); }
        }*/

        /// <summary>
        /// Initializes a new instance of the <see cref="ChangeTextFont"/> class.
        /// </summary>
        public ChangeTextFont()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ChangeTextFont"/> class.
        /// </summary>
        /// <param name="index">The line's index.</param>
        /// <param name="font">The font.</param>
        public ChangeTextFont(int index, Font font)
        {
            this.Index = index;
            this.Font = font;
        }

        /// <summary>
        /// Runs this instance.
        /// </summary>
        public override void Run()
        {
            oldFont = this.Context.CommentControl.Lines[Index].Font;
            this.Context.CommentControl.SetFont(this.Index, this.Font);
        }

        /// <summary>
        /// Undoes this instance.
        /// </summary>
        public override void Undo()
        {
            this.Context.CommentControl.SetFont(this.Index, this.oldFont);
        }
    }
}
